<?php
    /* 
     * @property int $id_user int
     * @property int $id_partner int
     * @property int $isadmin tinyint
     * @property int $isajf tinyint
     * @property string $username datetime
     * @property string $name datetime
     * @property string $firstname datetime
     * @property string $email varchar
     * @property string $password varchar
     */
    class WZModel_User extends WZ_Model_Abstract
    {
        protected $_name = 'user';
        protected $_primary = 'id_user';
        protected $_rowClass = 'WZModel_Row_User';
        
        protected $_referenceMap    = array(
            'Creator' => array(
                'columns'           => array('id_creator'),
                'refTableClass'     => 'User',
                'refColumns'        => 'id_user'
            ),
            'User' => array(
                'columns'           => array('id_user'),
                'refTableClass'     => 'User',
                'refColumns'        => 'id_user'
            ),
            'Profile' => array(
                'columns'           => array('id_profile'),
                'refTableClass'     => 'Profile',
                'refColumns'        => array('id_profile')
            ),
            'Client' => array(
                'columns'           => array('id_client'),
                'refTableClass'     => 'Client',
                'refColumns'        => array('id_client')
            )
        );
        
        /**
         * @param mix $value
         * @return WZModel_User
         */
        public function findByIdUser($value)
        {
            return $this->findOne(array('id_user = ?' => $value));
        }

        /**
         * @param mix $value
         * @return WZModel_User
         */
        public function findByUsername($value)
        {
            return $this->findOne(array('username = ?' => $value));
        }

        /**
         * @param mix $value
         * @return WZModel_User
         */
        public function findByEmail($value)
        {
            return $this->findOne(array('email = ?' => $value));
        }
    }
    
    class WZModel_Row_User extends Zend_Db_Table_Row_Abstract
    {
         /**
         * Set id_user (int)
         *
         * @param int $value
         * @return Model_Base_User
         */
        public function setIdUser($value)
        {
            $this->id_user = $value;
            return $this;
        }

        /**
         * Get id_user (int)
         *
         * @return int
         */
        public function getIdUser()
        {
            return $this->id_user;
        }

        /**
         * Set id_partner (int)
         *
         * @param int $value
         * @return Model_Base_User
         */
        public function setIdPartner($value)
        {
            $this->id_partner = $value;
            return $this;
        }

        /**
         * Get id_partner (int)
         *
         * @return int
         */
        public function getIdPartner()
        {
            return $this->id_partner;
        }

        /**
         * Set id_profile (tinyint)
         *
         * @param int $value
         * @return Model_Base_Profile
         */
        public function setIdProfile($value)
        {
            $this->id_profile = $value;
            return $this;
        }

        /**
         * Get id_profile (tinyint)
         *
         * @return int
         */
        public function getIdProfile()
        {
            return $this->id_profile;
        }
        
        /**
         * Set username (tinyint)
         *
         * @param string $value
         */
        public function setUsername($value)
        {
            $this->username = $value;
            return $this;
        }

        /**
         * Get username (tinyint)
         *
         * @return string
         */
        public function getUsername()
        {
            return $this->username;
        }
        
        /**
         * Set name (tinyint)
         *
         * @param string $value
         */
        public function setName($value)
        {
            $this->name = $value;
            return $this;
        }

        /**
         * Get name (tinyint)
         *
         * @return string
         */
        public function getName()
        {
            return $this->name;
        }

        /**
         * Set firstname (tinyint)
         *
         * @param string $value
         */
        public function setFirstName($value)
        {
            $this->firstname = $value;
            return $this;
        }

        /**
         * Get firstname (tinyint)
         *
         * @return string
         */
        public function getFirstName()
        {
            return $this->firstname;
        }
        
        public function setEmail($value)
        {
            $this->email = $value;
            return $this;
        }
        
        public function getEmail()
        {
            return $this->email;
        }
        
        function setPassword($value)
        {
            $this->password = md5($value);
            return $this;
        }

        /**
         * Create new Model_Appointment
         *
         * @param array $data
         * @return Model_Appointment
         */
        public function createAppointment($data)
        {
            $data['id_creator'] = $this->id_user;
            $table = new WZModel_Appointment();
            return $table->createRow($data);
        }

        /**
         * Find dependent Model_Appointment
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Zend_Db_Table_Rowset_Abstract
         */
        public function findAppointment()
        {
            return $this->findDependentRowset('WZModel_Appointment');
        }

        /**
         * Delete all dependant Model_Appointment matching condition.
         *
         * @param array $where
         * @return int Number of deleted rows
         */
        public function deleteAppointment($where = array())
        {
            $where['id_creator'] = $this->id_user;
            $table = new WZModel_Appointment();
            return $table->delete($where);
        }

        /**
         * Create new Model_Client
         *
         * @param array $data
         * @return Model_Client
         */
        public function createClient($data)
        {
            $data['id_user'] = $this->id_user;
            $table = new WZModel_Client();
            return $table->createRow($data);
        }

        /**
         * Find dependent Model_Client
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Zend_Db_Table_Rowset_Abstract
         */
        public function findClient()
        {
            return $this->findDependentRowset('WZModel_Client');
        }

        /**
         * Delete all dependant Model_Client matching condition.
         *
         * @param array $where
         * @return int Number of deleted rows
         */
        public function deleteClient($where = array())
        {
            $where['id_user'] = $this->id_user;
            $table = new WZModel_Client();
            return $table->delete($where);
        }

        /**
         * Create new Model_ClientHistory
         *
         * @param array $data
         * @return Model_ClientHistory
         */
        public function createClientHistory($data)
        {
            $data['id_creator'] = $this->id_user;
            $table = new WZModel_ClientHistory();
            return $table->createRow($data);
        }

        /**
         * Find dependent Model_ClientHistory
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Zend_Db_Table_Rowset_Abstract
         */
        public function findClientHistory()
        {
            return $this->findDependentRowset('WZModel_ClientHistory');
        }

        /**
         * Delete all dependant Model_ClientHistory matching condition.
         *
         * @param array $where
         * @return int Number of deleted rows
         */
        public function deleteClientHistory($where = array())
        {
            $where['id_creator'] = $this->id_user;
            $table = new WZModel_ClientHistory();
            return $table->delete($where);
        }

        /**
         * Create new Model_Product
         *
         * @param array $data
         * @return Model_Product
         */
        public function createProduct($data)
        {
            $data['id_user'] = $this->id_user;
            $table = new WZModel_Product();
            return $table->createRow($data);
        }

        /**
         * Find dependent Model_Product
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Zend_Db_Table_Rowset_Abstract
         */
        public function findProduct()
        {
            return $this->findDependentRowset('WZModel_Product');
        }

        /**
         * Delete all dependant Model_Product matching condition.
         *
         * @param array $where
         * @return int Number of deleted rows
         */
        public function deleteProduct($where = array())
        {
            $where['id_user'] = $this->id_user;
            $table = new WZModel_Product();
            return $table->delete($where);
        }

        /**
         * Create new Model_TeamHasUser
         *
         * @param array $data
         * @return Model_TeamHasUser
         */
        public function createTeamHasUser($data)
        {
            $data['id_user'] = $this->id_user;
            $table = new WZModel_TeamHasUser();
            return $table->createRow($data);
        }

        /**
         * Find dependent Model_TeamHasUser
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Zend_Db_Table_Rowset_Abstract
         */
        public function findTeamHasUser()
        {
            return $this->findDependentRowset('WZModel_TeamHasUser');
        }

        /**
         * Delete all dependant Model_TeamHasUser matching condition.
         *
         * @param array $where
         * @return int Number of deleted rows
         */
        public function deleteTeamHasUser($where = array())
        {
            $where['id_user'] = $this->id_user;
            $table = new WZModel_TeamHasUser();
            return $table->delete($where);
        }

        /**
         * Find parent Model_Partner
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Model_Partner
         */
        public function findPartner()
        {
            return $this->findParentRow('WZModel_Partner');
        }
        
        /**
         * Find parent Model_Profile
         *
         * @param string|array|Zend_Db_Table_Select $where
         * @param string|array $order
         * @param int $count
         * @param int $offset
         * @return Model_Partner
         */
        public function findProfile()
        {
            return $this->findParentRow('WZModel_Profile');
        }
    }